package atguigu.service.impl;

import atguigu.dao.AccountDao;
import atguigu.pojo.Account;
import atguigu.service.AccountService;
import atguigu.utils.ConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

@Service("noTCF")
public class AccountServiceImplNoTCF implements AccountService {
    //业务层依赖持久层
    @Autowired
    private AccountDao accountDao;

    /**
     * 转账的业务逻辑方法
     * 传递参数：付款人名，收款人名，转账金额
     *
     */
    @Override
    public void transfer(String toName, String inName, Double money)throws Exception  {

            Account toAccount = accountDao.queryAccount(toName);
            Account inAccount = accountDao.queryAccount(inName);
            toAccount.setMoney(toAccount.getMoney() - money);
            inAccount.setMoney(inAccount.getMoney() + money);
            int i = accountDao.updateAccount(toAccount);
            //int c = 1/0;
            int j = accountDao.updateAccount(inAccount);
            if (i>0 && j>0){
                System.out.println("转账成功！");
            }else {
                System.out.println("转账失败！");
            }



    }
}
